home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 12331 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.5 KB  |  64 lines

  1. Path: god.bel.alcatel.be!usenet
  2. From: bailleuf@btmaa.bel.alcatel.be (Frank Bailleul)
  3. Newsgroups: comp.lang.c++
  4. Subject: Exporting instantiated template classes in windows DLLs
  5. Date: Tue, 19 Mar 1996 13:23:23 GMT
  6. Organization: Alcatel Bell
  7. Message-ID: <4imc8p$3kk@btmpjg.god.bel.alcatel.be>
  8. NNTP-Posting-Host: 138.203.28.170
  9. X-Newsreader: Forte Free Agent 1.0.82
  10.  
  11. I am experimenting with DLLs in windows 95.  
  12. I use the MS Visual C++ 4.0 compiler.  
  13. How can I export an instantiated template class (if that is
  14. possible ?)
  15.  
  16. Example :
  17. --- begin ---
  18. #define EXPORT __declspec(dllexport)
  19.  
  20. class EXPORT MyClass {
  21.     ... // dont't care    
  22. };
  23.  
  24. typedef std::vector<MyClass> MyClassArray;
  25.  
  26. class EXPORT MyContainer {
  27. public:
  28.     MyClassArray /* yes, I want to make a copy of the list */
  29.         GetArray() const { return _data; }
  30. private:
  31.     MyClassArray _data;
  32. };
  33. --- end ---
  34.  
  35. How can I export MyClassArray ?
  36.  
  37. If I don't export the class, the compiler gives
  38. warnings, saying that MyClassArray should have
  39. a DLL interface.
  40.  
  41. OK, I don't export the class MyClassArray, so the client
  42. which uses the DLL has to define that class.
  43.  
  44. Example Client :
  45. --- begin ---
  46. typedef std::vector<MyClass*> MyClassArray;
  47.  
  48. int main() {
  49.     MyContainer cont;
  50.     { // local block 
  51.         MyClassArray ar = cont.GetArray();
  52.     } // ar is deleted *
  53.     return 0;
  54. }
  55.      
  56. Doing that, the executable client crashes at point *,
  57. where MyClassArray is destructed.
  58.  
  59. Could anyone explain me :
  60. 1. if an instantiated  template class can be exported
  61.     and if it can, how to do it ?
  62. 2. why the program crashed ?
  63.  
  64.